//- Copyright (C) 2018-2022 Chatopera Inc, <https://www.chatopera.com>
//- 
//- Licensed under the Apache License, Version 2.0 (the "License");
//- you may not use this file except in compliance with the License.
//- You may obtain a copy of the License at
//- 
//-  http://www.apache.org/licenses/LICENSE-2.0
//- 
//-  Unless required by applicable law or agreed to in writing, software
//- distributed under the License is distributed on an "AS IS" BASIS,
//-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//- See the License for the specific language governing permissions and
//- limitations under the License.
include /mixins/dic.mixin.pug

.uk-layui-form
    form.layui-form(action="/apps/customer/save.html", method="post")
        input(type="hidden", name="entcustomer.shares", value="all")
        input(type="hidden", name="contacts.shares", value="all")
        .layui-collapse
            .layui-colla-item
                h2.layui-colla-title 基本信息
                .layui-colla-content.layui-show
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 获得时间：
                            .layui-input-inline
                                input#getdate.layui-input(type="text", name="entcustomer.touchtime", readonly="readOnly", lay-verify="date", autocomplete="off")
                                i.layui-icon(style="position: absolute;right: 3px;top: 6px;font-size: 25px;") 
                        .layui-inline
                            font(color="red") *（必填项）
                            |  (您得到此客户的时间)
                        .layui-inline
                            label.layui-form-label(style="width:60px") 类型：
                            .layui-input-inline(style="width:218px;margin-right:0px;padding-top:9px;")
                                input(type="radio", name="entcustomer.etype", value="enterprise", title="企业客户", checked="", lay-filter="etype")
                                input(type="radio", name="entcustomer.etype", value="personal", title="个人客户", lay-filter="etype")
            .layui-colla-item
                h2.layui-colla-title 企业信息
                .layui-colla-content.layui-show
                    .layui-form-item
                        .layui-inline
                            label#cusname.layui-form-label 客户名称：
                            .layui-input-inline
                                input.layui-input(type="text", name="entcustomer.name", required="", lay-verify="customer_username", autocomplete="off")
                        .layui-inline
                            font(color="red") *（必填项）
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 联系电话：
                            .layui-input-inline
                                input.layui-input(type="text", name="entcustomer.phone", autocomplete="off")
                        .layui-inline.uckefu-inline
                            label.layui-form-label 电子邮件：
                            .layui-input-inline
                                input.layui-input(type="text", name="entcustomer.email", lay-verify="entemail", autocomplete="off")
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 城市：
                            .layui-input-inline(style="width:80px;")
                                +sysDicSelect('com.dic.address.area','entcustomer.province','',{'lay-ignore': true},'width:85px;')
                        .layui-inline
                            #city.layui-input-inline(style="width:80px;")
                                +sysDicSelect('com.dic.address.city','entcustomer.city','',{'lay-ignore': true},'width:86px;')
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 客户地址：
                            .layui-input-inline(style="width: 664px;")
                                input.layui-input(type="text", name="entcustomer.address", autocomplete="off")
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 客户类型：
                            .layui-input-inline
                                +sysDicSelect('com.dic.contacts.entype','entcustomer.ekind',ekind,{'lay-ignore': true})
                        .layui-inline.uckefu-inline
                            label.layui-form-label 客户级别：
                            .layui-input-inline
                                +sysDicSelect('com.dic.contacts.elevel','entcustomer.elevel','',{'lay-ignore': true})
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 客户来源：
                            .layui-input-inline
                                +sysDicSelect('com.dic.contacts.esource','entcustomer.esource','',{'lay-ignore': true})
                        .layui-inline.uckefu-inline
                            label.layui-form-label 成熟度：
                            .layui-input-inline
                                +sysDicSelect('com.dic.contacts.maturity','entcustomer.maturity','',{'lay-ignore': true})
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 行业：
                            .layui-input-inline
                                +sysDicSelect('com.dic.contacts.industry','entcustomer.industry','',{'lay-ignore': true})
                        .layui-inline.uckefu-inline
                            label.layui-form-label 客户状态：
                            .layui-input-inline
                                +sysDicSelect('com.dic.contacts.validstatus','entcustomer.validstatus','',{'lay-ignore': true})
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 客户说明：
                            .layui-input-inline(style="width: 664px;")
                                textarea.layui-textarea(name="entcustomer.description", placeholder="请输入内容", style="resize:none;")
            #contacts_info.layui-colla-item
                h2.layui-colla-title
                    | 联系人信息
                    font(color="red") （提示：创建企业信息后可在个人客户里添加更多联系人）
                .layui-colla-content.layui-show
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 姓名：
                            .layui-input-inline
                                input.layui-input(type="text", name="contacts.name", autocomplete="off", lay-verify="customer_username")
                        .layui-inline.uckefu-inline
                            label.layui-form-label 性别：
                            .layui-input-inline(style="width:auto;")
                                .layui-input-block
                                    input(type="radio", name="contacts.gender", value="男", title="男")
                                    input(type="radio", name="contacts.gender", value="女", title="女", checked="")
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 生日：
                            .layui-input-inline
                                input#birthday.layui-input(type="text", name="contacts.cusbirthday", autocomplete="off")
                                i.layui-icon(style="position: absolute;right: 3px;top: 6px;font-size: 25px;") 
                        .layui-inline.uckefu-inline
                            label.layui-form-label 座机电话：
                            .layui-input-inline(style="width:auto;")
                                .layui-input-block
                                    input.layui-input(type="text", name="contacts.phone", autocomplete="off")
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 电子邮件：
                            .layui-input-inline
                                input.layui-input(type="text", name="contacts.email", autocomplete="off", lay-verify="entemail")
                        .layui-inline.uckefu-inline
                            label.layui-form-label 手机号：
                            .layui-input-inline(style="width:auto;")
                                .layui-input-block
                                    input.layui-input(type="text", name="contacts.mobile", autocomplete="off")
                    .layui-form-item
                        .layui-inline
                            label.layui-form-label 联系人地址：
                            .layui-input-inline(style="width: 660px;")
                                input.layui-input(type="text", name="contacts.address", autocomplete="off")
        .layui-form-button
            .layui-button-block
                button.layui-btn(lay-submit="", lay-filter="formDemo") 立即提交
                button.layui-btn.layui-btn-original(type="reset") 重置
script.
    //Demo
    layui.use('form', function () {
        var form = layui.form();
        form.render(); //更新全部
        form.verify({
            entemail: function (value) {
                if (value != "" && !new RegExp(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/).test(value)) {
                    return '请输入正确的电子邮箱地址';
                }
            },
            customer_username: function (value) {
                if (value.length > 100) {
                    return "用户姓名不能超过100字";
                }
            }
        });
        form.on("radio(etype)", function (data) {
            if (data.value == "enterprise") {
                $('#contacts_info').show();
                $('#cusname').text("客户名称：");
            } else {
                $('#contacts_info').hide();
                $('#cusname').text("客户姓名：");
            }
        });
    });
    layui.use('element', function () {
        var element = layui.element();
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var date = {
            min: '1950-01-01 00:00:00',
            max: laydate.now(),
            istoday: false
        };
        document.getElementById('getdate').onclick = function () {
            date.elem = this;
            laydate(date);
        }
        document.getElementById('birthday').onclick = function () {
            date.elem = this;
            laydate(date);
        }
    });
    $('#entcustomer_province').change(function () {
        loadURL('/res/dic.html?id=' + $(this).val() + "&name=entcustomer.city&attr=lay-ignore&style=width:85px;", '#entcustomer_city');
    })
